<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@page import="com.is.model.User"%>
<%@page import="com.is.control.UserControl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">  
	<meta http-equiv="keywords" content="留学生,nenu,东北师大,东北师范大学">
	<meta http-equiv="description" content="东北师范大学预科部教学管理系统">
	<link rel="shortcut icon" href="../resources/image/favicon.ico" />
	<script type="text/javascript" src="../resources/js/jquery-1.8.1.js"></script>
	<link rel="stylesheet" type="text/css" href="../resources/css/common.css">
	<link rel="stylesheet" type="text/css" href="../resources/css/login.css">
	<!--[if lte IE 6]>
	<style type="text/css">
		.iewarn{width:100%; height:20px; background:#fff; display:block;color:#000;}
	</style>
	<script src="../resources/js/ie6_png.js" type="text/javascript"></script>
	<script type="text/javascript">
	 DD_belatedPNG.fix('div, ul, table, tr, td, img, li, input , a,span');
	 window.onload = function(){
	 	 var warn = document.createElement("A");
		 warn.setAttribute("href","http://www.firefox.com.cn/download/");
		 warn.setAttribute("className","iewarn");
		 var text = document.createTextNode("您的浏览器版本过低，为了您的体验。请下载升级");
		 warn.appendChild(text);
		 document.body.insertBefore(warn,document.body.firstChild);
	 }
	</script>
	<![endif]-->
	<script type='text/javascript'>
		$(function(){
			var path = "../resources/background/img";
			var imgnum = Math.floor(Math.random()*8)+1 ;
			var img = document.getElementById("img");
				setInterval(function(){
					var w = $(window).width();
					var h = $(window).height();
					img.height = h;
					img.width = w;
					$(".load").css("top",h/2 - 100);
				},100);
				$("#all").hide();
				img.src = path + imgnum + ".jpg";
				var i = 1;
				var interval = setInterval(function(){
					i--;
					if(i==0){
						$(".load").hide();
						$("#all").fadeIn(300);
						clearInterval(interval);
					}
				},1000)
			if($(".container").size() >0){
				var xhr = (window.XMLHttpRequest)?new XMLHttpRequest:new ActiveXObject("Microsoft.XMLHTTP");
				var submit = document.forms[0];
				submit.onsubmit = function(e){		
					if(e && e.preventDefault){
						e.preventDefault();
					}
					else{
						window.event.returnValue = false;
					}
					var username = document.getElementsByName("username")[0].value;
					var password = document.getElementsByName("password")[0].value;
					var cookie =  0;
					if(document.getElementsByName("cookie")[0].checked){
						cookie =  document.getElementsByName("cookie")[0].value;
					}
					xhr.onreadystatechange = function(){
						if(xhr.readyState == 4 && xhr.status == 200){
							var message = xhr.responseXML.getElementsByTagName("status")[0].firstChild.nodeValue;
							document.getElementById("message").innerHTML = "<font color='red'>"+message+"</font>";
							var role = xhr.responseXML.getElementsByTagName("role");
							if(role.length>0){
								var uid = xhr.responseXML.getElementsByTagName("uid")[0].firstChild.nodeValue;
								if(role[0].firstChild.nodeValue =="普通用户"){
									window.location.href="../pages/temp.jsp";
								}
								else if(role[0].firstChild.nodeValue =="管理员"){
									window.location.href="../pages/temp.jsp?id=" + uid;
								} else{
									document.getElementById("message").innerHTML = "<font color='red'>非法用户</font>";
								}
							}
						}
					}
					xhr.open("post","login_do.jsp",true);
					xhr.setRequestHeader('Content-type','application/x-www-form-urlencoded');
					xhr.send("username="+username+"&password="+password+"&cookie="+cookie);
				}
			}
			/*页面*/
				if($(".container").size() >0){
					$(".txt")
					.focus(function(){
						$(this).parent()
						.removeClass("b1")
						.addClass("b2")
					})
					.blur(function(){
						$(this).parent()
						.removeClass("b2")
						.addClass("b1")
					})
					.keyup(function(){
						if($(this).val() != ""){
							$(this).prev().hide();
						} else{
							$(this).prev().show();
						}
					});
					$(":image")
					.mouseover(function(){
						$(this).attr("src","../resources/css/slice/login24_10.png");	
					})
					.mouseout(function(){
						$(this).attr("src","../resources/css/slice/login24_04.png");	
					})
					.focus(function(){
						$(this).attr("src","../resources/css/slice/login24_03.png");	
					})
					$(".check1").toggle(
						function(){
							$(this).addClass("checked");
							$(":checkbox").attr("checked",true);
						},
						function(){
							 $(this).removeClass("checked");
							 $(":checkbox").attr("checked",false);
					})
				}
		})
	</script>
	<title>管理员登录</title>
</head>
<body>
	<div class="load"></div>
	<div id = "all">
		<div class="background">
    		<img id="img" alt="" src=""/>
    	</div>
		<div>
			<div class="head hide">
				东北师范大学外国留学生预科部教学管理系统				
			</div>
		</div>
		<div class='main br3'>
<%
            Cookie cks[] = request.getCookies();
            String uid="";
            boolean isCookie=false;
            String pwd="";
            if(cks!=null){
            for(Cookie c:cks){
                 if(c.getName().equals("CK_UID")&&c.getValue()!=null&&!c.getValue().equals("")){
                      uid =c.getValue();
                      isCookie=true;
                 }
                 if(c.getName().equals("CK_PWD")&&c.getValue()!=null&&!c.getValue().equals("")){
		                pwd =c.getValue();
		            }
            }
            if(isCookie){
             User cu = UserControl.getUserById(Integer.parseInt(uid));
	             if(cu!=null&&cu.getPassword().equals(pwd)){
	             	session.setAttribute("user",cu);
	             	session.setAttribute("uid",uid);
	             %>
	            <p class="ok"><span>已检测到账号：<%=cu.getUsername() %></span>
			       <a class="qlogin" href="../pages/temp.jsp">快速登录</a>
			       <a class='logout' href="logout.jsp">注销</a>
			    </p> 
	             <% 
	             }else{
	            	 %>
	            	 
	            	 <form>
	            	 	<ul class="container">
	            	 		<li class="pr inputs b1"><label class="pa user">用户名</label><input tabindex="1" autocomplete="off" name='username' class="txt pa" type="text"></li>
	            	 		<li class="pr inputs b1"><label class="pa user">密码</label><input tabindex="2" autocomplete="off"  name='password' class="txt pa"  type="password"/></li>
	            	 		<li><input type="image" src='../resources/css/slice/login24_04.png'></li>
	            	 		<li><p class="tag"><span class="check1 checked" ><input type="checkbox" value="1" checked="true" name="cookie"></span>下次自动登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style="color:#6E68C8" href="/InterStu/studentRead.jsp" target="_blank">学生入口</a></p></li>
	            	 		<li><p id='message' class="tag">欢迎您访问！</p></li>
	            	 	</ul>
	            	 </form>
	            	 <%
             }}else{
 %>
 
<form>
	<ul class="container">
		<li class="pr inputs b1"><label class="pa user">用户名</label><input tabindex="1" autocomplete="off" name='username' class="txt pa" type="text"></li>
		<li class="pr inputs b1"><label class="pa user">密码</label><input tabindex="2" autocomplete="off"  name='password' class="txt pa"  type="password"/></li>
		<li><input type="image" src='../resources/css/slice/login24_04.png'></li>
		<li><p class="tag"><span class="check1 checked" ><input type="checkbox" value="1" checked="true"  name="cookie"></span>下次自动登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a style="color:#6E68C8" href="/InterStu/studentRead.jsp" target="_blank">学生入口</a></p></li>
		<li><p id='message' class="tag">欢迎您访问！</p></li>
	</ul>
</form>
<%
 }}%>
 </div>
		<p class="pa copy"> &copy;东北师范大学留学生预科部&nbsp;版权所有&nbsp;&nbsp;&nbsp;&nbsp;蓝旭工作室&nbsp;开发</p>
		<div class="footer"></div>
		</div>
</body>
</html>